package org.example.demo3.service.impl;

import lombok.RequiredArgsConstructor;
import org.example.demo3.service.EmailService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * 邮件服务实现类
 */
@Service
@RequiredArgsConstructor
public class EmailServiceImpl implements EmailService {

    private final JavaMailSender mailSender;
    
    @Value("${spring.mail.username}")
    private String fromEmail;
    
    @Value("${app.name:校园二手交易平台}")
    private String appName;

    @Override
    public void sendResetPasswordEmail(String to, String username, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromEmail);
        message.setTo(to);
        message.setSubject(appName + " - 重置密码验证码");
        
        String content = "亲爱的用户 " + username + "：\n\n"
                + "您正在进行重置密码操作，验证码为：" + code + "\n\n"
                + "验证码有效期为15分钟，请勿将验证码泄露给他人。\n\n"
                + "如果您没有进行此操作，请忽略此邮件。\n\n"
                + "此致\n"
                + appName + " 团队";
        
        message.setText(content);
        mailSender.send(message);
    }
} 